package day16.FanSe.FS04;

import java.lang.reflect.Method;

public class Text {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
//        method();
//        method2();
//        method3();
        Class<?> aClass = Class.forName("day16.FanSe.FS04.Student");
//        获取一个成员方法
        Method method = aClass.getDeclaredMethod("show");
        System.out.println(method);
    }

    private static void method3() throws ClassNotFoundException, NoSuchMethodException {
        Class<?> aClass = Class.forName("day16.FanSe.FS04.Student");
//        获取一个无参的方法
        Method method1 = aClass.getMethod("function1");
        System.out.println(method1);
        System.out.println("-------");
//        获取一个有参的方法
        Method method2 = aClass.getMethod("function2", String.class);
        System.out.println(method2);
    }

    private static void method2() throws ClassNotFoundException {
        Class<?> aClass = Class.forName("day16.FanSe.FS04.Student");
//        返回所有成员方法对象的数组,不包括继承的
        Method[] methods = aClass.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }

    private static void method() throws ClassNotFoundException {
        Class<?> aClass = Class.forName("day16.FanSe.FS04.Student");
//        返回所有公共方法
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }
}
